<template>
    <div class="container">
        <h1 class="text-center">Изменение данных эксперта</h1>
        <b-form @submit.prevent="updateExpert">
            <b-form-group  id="fieldset-last-name" label="Введите Фамилию:" label-for="input-1">
                <b-form-input
                    id="input-1"
                    v-model="lastName"
                    type="text"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group  id="fieldset-first-name" label="Введите Имя:" label-for="input-1">
                <b-form-input
                    id="input-1"
                    v-model="firstName"
                    type="text"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group  id="fieldset-patronymic" label="Введите Отчество:" label-for="input-1">
                <b-form-input
                    id="input-1"
                    v-model="patronymic"
                    type="text"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group
                id="fieldset-2"
                label="Ваша должность:"
                label-for="input-2"
            >
                <b-form-input
                    id="input-2"
                    v-model="position"
                    type="text"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group id="fieldset-3" label="Оброзование:" label-for="input-3">
                <b-form-input
                    id="input-3"
                    v-model="education"
                    type="text"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group id="fieldset-4" label="Опыт работы:" label-for="input-4">
                <b-form-input
                    id="input-4"
                    v-model="experience"
                    type="number"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group id="fieldset-6" label="Адрес:" label-for="input-6">
                <b-form-input
                    id="input-6"
                    v-model="address"
                    type="text"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group
                id="fieldset-7"
                label="Ввеедие нормер телефона:"
                label-for="input-7"
            >
                <b-form-input
                    id="input-7"
                    type="tel"
                    v-model="phoneNumber"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group
                id="fieldset-8"
                label="Ввеедие email:"
                label-for="input-8"
            >
                <b-form-input
                    id="input-8"
                    v-model="email"
                    type="email"
                    required
                ></b-form-input>
            </b-form-group>

            <b-form-group
                id="fieldset-9"
                label="Информация об отпуске и больничных:"
                label-for="input-9"
            >
                <b-form-input
                    id="input-9"
                    type="text"
                    v-model="vacationInfo"
                    required
                ></b-form-input>
            </b-form-group>
            <b-button type="submit" variant="primary">Изменить</b-button>
        </b-form>
        <b-button @click="deleteExpert" variant="primary">Удалить эксперта</b-button>
        <h5>{{ notification }}</h5>
    </div>
</template>

<script>
export default {
    data() {
        return {
            firstName: "",
            lastName: "",
            patronymic: "",
            position: "",
            education: "",
            experience: "",
            address: "",
            phoneNumber: "",
            email: "",
            vacationInfo: "",
            notification: ""
        };
    },
    methods: {
        async updateExpert() {
            await this.$http.put("/expert/update/" + this.$route.params.id, {
                "first_name": this.firstName,
                "last_name": this.lastName,
                "patronymic": this.patronymic,
                "position": this.position,
                "education": this.education,
                "experience": this.experience,
                "address": this.address,
                "phone_number": this.phoneNumber,
                "email": this.email,
                "vacation_information": this.vacationInfo 

            })
            .then(response => {
                console.log(response)
                this.$router.push({path: "/"}) 
            })
            .catch(e => {
                this.errors.push(e)
            })
        },
        async deleteExpert() {
            await this.$http.delete("/expert/delete/" + this.$route.params.id)
                .then(response => {
                    console.log(response)
                    this.$router.push({path: "/"}) 
                })
                .catch(e => {
                    this.notification = "Вы не можете удалить эксперта, который участвует в экспертизе, сначала удалите экспертизу в которой он состоит"
                    this.errors.push(e)
                })
        }
    },
    created() {
        this.$http.get("/expert/" + this.$route.params.id)
            .then(response => {
                this.firstName = response.data.first_name
                this.lastName = response.data.last_name
                this.patronymic = response.data.patronymic
                this.position = response.data.position,
                this.education = response.data.education,
                this.experience = response.data.experience,
                this.address = response.data.address,
                this.phoneNumber = response.data.phone_number,
                this.email = response.data.email,
                this.vacationInfo = response.data.vacation_information
                this.expertises = response.data.expertises

            })
    }
};
</script>

<style>
</style>
